<?php
class BlogUserInfo
{
    static $instance = null;
    protected $user;
    protected $blogInfo;

    /**
     * 
     * returns blog title of this instanse
     */
    public static function getBlogTitle()
    {
        return self::getInstance()->getBlogInfo()->getTitle();
    }
    /**
     * 
     * singlethon,returns one instance of BlogUserInfo
     */
    public static function getInstance() 
    {
        if (!isset(self::$instance)) {
            self::$instance = new BlogUserInfo();
        }

        return self::$instance;
    }
    
    /**
     * 
     * If is info about user, retrievs BlogInfo by user, or returns new one
     * if user not found, user is new user
     */
    public function BlogUserInfo()
    {
        $this->user = new User();
        $this->blogInfo = new BlogInfo();
        $nick = sfContext::getInstance()->getRequest()->getParameter('nick', '');
        $user = User::getIdByNick($nick);
        if( !$user )
        {
            $user = get_user_id();
        }
        if( $user )
        {
            $this->user = UserPeer::retrieveByPK($user);
            $blogInfo = BlogInfo::getBlogInfoByUser($this->user->getId());
            if( $blogInfo )
            {
                $this->blogInfo = $blogInfo;
            }
        }
    }
    
    public function getUser()
    {
        return $this->user;
    }
    public function getBlogInfo()
    {
        return $this->blogInfo;
    }
    /**
     * 
     * returns array info about blog banners gallery
     */
    public static function getPhotoDirs()
    {
        $allDirs = sfConfig::get('app_symcms_files_bloggallery');
        if(empty($allDirs))
        {
            $allDirs = array();
        }
        return $allDirs;
    }
}